//
//  HLRtcExitView.m
//  YueYue
//
//  Created by hulu001 on 2023/9/15.
//

#import "HLRtcExitView.h"

@interface HLRtcExitView ()

@property (nonatomic, strong) UIView *containerView;
@property (nonatomic, strong) UIImageView *backView;
@property (nonatomic, strong) UIImageView *iconView;

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *detailLabel;

@property (nonatomic, strong) QMUIButton *sureButton;
@property (nonatomic, strong) QMUIButton *cancelButton;


@end

@implementation HLRtcExitView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupView];
    }
    return self;
}


- (void)setupView
{
    self.containerView = [[UIView alloc] init];
    _containerView.layer.masksToBounds = YES;
    _containerView.layer.cornerRadius = 16;
    _containerView.backgroundColor = UIColorWhite;
    [self addSubview:_containerView];
    [_containerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(30);
        make.size.mas_equalTo(CGSizeMake(300, 192));
    }];
    
    UIImage *backImage = [UIImage qmui_imageWithGradientColors:@[[HLMainColor colorWithAlphaComponent:0.6], [UIColorWhite colorWithAlphaComponent:0.1]] type:QMUIImageGradientTypeVertical locations:@[@0, @1] size:CGSizeMake(300, 62) cornerRadiusArray:nil];
    self.backView = [[UIImageView alloc] initWithImage:backImage];
    [_containerView addSubview:_backView];
    [_backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(0);
        make.height.mas_equalTo(92);
    }];
    
    self.iconView = [[UIImageView alloc] initWithImage:UIImageMake(@"rtc_exit_icon")];
    [self addSubview:_iconView];
    [_iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.centerY.equalTo(_containerView.mas_top);
    }];
    
    self.titleLabel = [[UILabel alloc] qmui_initWithFont:UIFontMediumMake(18) textColor:HLTextColor1];
    _titleLabel.text = @"温馨提示";
    _titleLabel.textAlignment = NSTextAlignmentCenter;
    [_containerView addSubview:_titleLabel];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.right.mas_equalTo(-10);
        make.top.mas_equalTo(50);
    }];
    
    self.detailLabel = [[UILabel alloc] qmui_initWithFont:UIFontMake(14) textColor:HLTextColor2];
    _detailLabel.text = @"嘤嘤嘤～哥哥真的要离开我吗";
    _detailLabel.textAlignment = NSTextAlignmentCenter;
    [_containerView addSubview:_detailLabel];
    [_detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(_titleLabel);
        make.top.equalTo(_titleLabel.mas_bottom).offset(10);
    }];
    
    
    self.sureButton = [[QMUIButton alloc] init];
    [_sureButton setTitle:@"狠心离开" forState:UIControlStateNormal];
    [_sureButton setTitleColor:HLTextColor1 forState:UIControlStateNormal];
    [_sureButton.titleLabel setFont:UIFontMake(15)];
    _sureButton.cornerRadius = 22;
    _sureButton.backgroundColor = HLBackgroundColor;
    [_containerView addSubview:_sureButton];
    [_sureButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(124, 44));
        make.bottom.mas_equalTo(-30);
        make.left.mas_equalTo(12);
    }];
    
    self.cancelButton = [[QMUIButton alloc] init];
    [_cancelButton setTitle:@"再聊一会" forState:UIControlStateNormal];
    [_cancelButton setTitleColor:UIColorWhite forState:UIControlStateNormal];
    [_cancelButton.titleLabel setFont:UIFontMake(15)];
    _cancelButton.cornerRadius = 22;
    _cancelButton.backgroundColor = HLMainColor;
    [_containerView addSubview:_cancelButton];
    [_cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.bottom.equalTo(_sureButton);
        make.right.mas_equalTo(-12);
    }];
}

+ (void)showWithCallback:(HLCommonCallbackBoolBlock)callback
{
    [self showWithTitle: @"温馨提示" Content:@"嘤嘤嘤～哥哥真的要离开我吗" LeftButtonTitle:@"狠心离开" RightButtonTitle:@"再聊一会" Callback:callback];
}

+ (void)showWithTitle:(NSString *)title
              Content:(NSString *)content
      LeftButtonTitle:(NSString *)left
     RightButtonTitle:(NSString *)right
             Callback:(HLCommonCallbackBoolBlock)callback
{

    CGFloat height = 330;
    HLRtcExitView *contentView = [[HLRtcExitView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, height)];
    contentView.titleLabel.text = title;
    contentView.detailLabel.text = content;
    [contentView.sureButton setTitle:left forState:UIControlStateNormal];
    [contentView.cancelButton setTitle:right forState:UIControlStateNormal];
    
    QMUIModalPresentationViewController *modalViewController = [[QMUIModalPresentationViewController alloc] init];

    modalViewController.contentView = contentView;
    modalViewController.modal = YES;
    [modalViewController showWithAnimated:YES completion:nil];
    [contentView.sureButton setQmui_tapBlock:^(__kindof UIControl *sender) {
        [modalViewController hideWithAnimated:YES completion:nil];
        if (callback){
            callback(YES);
        }
    }];
    
    [contentView.cancelButton setQmui_tapBlock:^(__kindof UIControl *sender) {
        [modalViewController hideWithAnimated:YES completion:nil];
        if (callback){
            callback(NO);
        }
    }];
}

@end
